package no.ntnu.fp.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;


import org.jdesktop.swingx.JXDatePicker;
import javax.swing.JList;
import javax.swing.JSpinner;
import javax.swing.JComboBox;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.Font;


public class NewAppointmentWindow extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtTittel;
	private JRadioButton rdbtnJobb;
	private JRadioButton rdbtnPrivat;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JLabel lblInterneDeltakere;
	private JLabel lblEksterneDeltakere;
	private JLabel lblVelgInterneDeltagere;
	private JLabel lblVelgRom;
	private JRadioButton rdbtnAutomatisk;
	private JRadioButton rdbtnManuell;
	private JLabel lblRom;
	private JComboBox comboBox;
	private JTextField txtSk;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextArea txtrRomLedig;
	private JList list;
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private JLabel lblTittel;
	private JLabel lblBeskrivelse;
	private JLabel lblOpprettAvtale;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			NewAppointmentWindow dialog = new NewAppointmentWindow();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public NewAppointmentWindow() {
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		setBounds(100, 100, 790, 549);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			txtTittel = new JTextField();
			txtTittel.setBounds(57, 114, 187, 22);
			txtTittel.setToolTipText("Tittel");
			contentPanel.add(txtTittel);
			txtTittel.setColumns(10);
		}
		
		JTextArea txtrBeskrivelse = new JTextArea();
		txtrBeskrivelse.setLineWrap(true);
		txtrBeskrivelse.setWrapStyleWord(true);
		txtrBeskrivelse.setToolTipText("Beskrivelse");
		txtrBeskrivelse.setBounds(12, 242, 216, 161);
		contentPanel.add(txtrBeskrivelse);
		
		/*final JLabel label = new JLabel();
		label.setText("Choose Date by selecting below.");
		label.setBounds(12, 81, 171, 22);
		contentPanel.add(label);
		 */
		final JXDatePicker datePicker = new JXDatePicker();
		datePicker.setBounds(57, 152, 77, 22);
		contentPanel.add(datePicker);
		
		rdbtnJobb = new JRadioButton("Jobb");
		rdbtnJobb.setBounds(108, 55, 66, 25);
		rdbtnJobb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(rdbtnJobb.isSelected()){
					lblInterneDeltakere.setEnabled(true);
					lblEksterneDeltakere.setEnabled(true);
					lblVelgInterneDeltagere.setEnabled(true);
					lblVelgRom.setEnabled(true);
					rdbtnAutomatisk.setEnabled(true);
					rdbtnManuell.setEnabled(true);
					lblRom.setEnabled(true);
					if(rdbtnAutomatisk.isSelected()){
						comboBox.setEnabled(false);
					}
					else{
						comboBox.setEnabled(true);
					}
					txtSk.setEnabled(true);
					list.setEnabled(true);
					textField_1.setEnabled(true);
					txtrRomLedig.setVisible(true);
				}
			}
		});
		rdbtnJobb.setSelected(true);
		buttonGroup.add(rdbtnJobb);
		contentPanel.add(rdbtnJobb);
		
		rdbtnPrivat = new JRadioButton("Privat");
		rdbtnPrivat.setBounds(178, 55, 66, 25);
		rdbtnPrivat.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(rdbtnPrivat.isSelected()){
					lblInterneDeltakere.setEnabled(false);
					lblEksterneDeltakere.setEnabled(false);
					lblVelgInterneDeltagere.setEnabled(false);
					lblVelgRom.setEnabled(false);
					rdbtnAutomatisk.setEnabled(false);
					rdbtnManuell.setEnabled(false);
					lblRom.setEnabled(false);
					comboBox.setEnabled(false);
					txtSk.setEnabled(false);
					list.setEnabled(false);
					textField_1.setEnabled(false);
					txtrRomLedig.setVisible(false);
				}
				
			}
		});
		buttonGroup.add(rdbtnPrivat);
		contentPanel.add(rdbtnPrivat);
		{
			JLabel lblVelgAvtaletype = new JLabel("Velg avtaletype:");
			lblVelgAvtaletype.setBounds(12, 59, 88, 16);
			contentPanel.add(lblVelgAvtaletype);
		}
		
		list = new JList();
		list.setBounds(257, 115, 195, 225);
		contentPanel.add(list);
		
		txtSk = new JTextField();
		txtSk.setBounds(257, 81, 198, 22);
		txtSk.setText("Søk");
		contentPanel.add(txtSk);
		txtSk.setColumns(10);
		
		SpinnerModel model = new SpinnerDateModel();
		JSpinner spinner = new JSpinner(model);
		spinner.setBounds(57, 196, 66, 22);

		JComponent editor = new JSpinner.DateEditor(spinner, "HH:mm");
		spinner.setEditor(editor);
		spinner.setValue(new Date());
		contentPanel.add(spinner);
		
		JLabel lblStart = new JLabel("Start:");
		lblStart.setBounds(12, 199, 52, 16);
		contentPanel.add(lblStart);
		
		JLabel lblSlutt = new JLabel("Slutt:");
		lblSlutt.setBounds(135, 199, 39, 16);
		contentPanel.add(lblSlutt);
		
		SpinnerModel model1 = new SpinnerDateModel();
		JSpinner spinner_1 = new JSpinner(model1);
		JComponent editor1 = new JSpinner.DateEditor(spinner_1, "HH:mm");
		spinner_1.setEditor(editor1);
		spinner_1.setValue(new Date());
		spinner_1.setBounds(178, 196, 66, 22);
		contentPanel.add(spinner_1);
		
		textField = new JTextField();
		textField.setBounds(57, 435, 171, 22);
		contentPanel.add(textField);
		textField.setColumns(10);
		
		JLabel lblSted = new JLabel("Sted:");
		lblSted.setBounds(12, 438, 52, 16);
		contentPanel.add(lblSted);
		
		lblInterneDeltakere = new JLabel("Antall interne deltakere:");
		lblInterneDeltakere.setBounds(467, 53, 150, 16);
		contentPanel.add(lblInterneDeltakere);
		
		lblEksterneDeltakere = new JLabel("Antall eksterne deltakere:");
		lblEksterneDeltakere.setBounds(467, 84, 150, 16);
		contentPanel.add(lblEksterneDeltakere);
		
		textField_1 = new JTextField();
		textField_1.setBounds(629, 81, 77, 22);
		contentPanel.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(629, 56, 77, 22);
		textField_2.setEditable(false);
		contentPanel.add(textField_2);
		textField_2.setColumns(10);
		
		lblVelgRom = new JLabel("Velg rom:");
		lblVelgRom.setBounds(464, 137, 52, 16);
		contentPanel.add(lblVelgRom);
		
		rdbtnAutomatisk = new JRadioButton("Automatisk");
		rdbtnAutomatisk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(rdbtnAutomatisk.isSelected()){
					comboBox.setEnabled(false);
				}
			}
		});
		rdbtnAutomatisk.setBounds(528, 133, 88, 24);
		buttonGroup_1.add(rdbtnAutomatisk);
		rdbtnAutomatisk.setSelected(true);
		contentPanel.add(rdbtnAutomatisk);
		
		rdbtnManuell = new JRadioButton("Manuell");
		rdbtnManuell.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(rdbtnManuell.isSelected()){
					comboBox.setEnabled(true);
				}
			}
		});
		rdbtnManuell.setBounds(630, 133, 76, 24);
		buttonGroup_1.add(rdbtnManuell);
		contentPanel.add(rdbtnManuell);
		
		lblRom = new JLabel("Rom:");
		lblRom.setBounds(464, 183, 52, 16);
		contentPanel.add(lblRom);
	
		comboBox = new JComboBox();
		comboBox.setEnabled(false);
		comboBox.setBounds(628, 180, 78, 22);
		contentPanel.add(comboBox);
		
		Canvas canvas = new Canvas();
		canvas.setBounds(455, -60, 1, 444);
		canvas.setEnabled(false);
		canvas.setBackground(SystemColor.desktop);
		canvas.setForeground(Color.WHITE);
		contentPanel.add(canvas);
		
		Canvas canvas_1 = new Canvas();
		canvas_1.setBounds(245, -60, 1, 444);
		canvas_1.setBackground(SystemColor.desktop);
		contentPanel.add(canvas_1);
		
		lblVelgInterneDeltagere = new JLabel("Velg interne deltagere:");
		lblVelgInterneDeltagere.setBounds(256, 53, 150, 16);
		contentPanel.add(lblVelgInterneDeltagere);
		
		JLabel lblDato = new JLabel("Dato:");
		lblDato.setBounds(12, 155, 52, 16);
		contentPanel.add(lblDato);
		
		txtrRomLedig = new JTextArea();
		txtrRomLedig.setBounds(464, 224, 239, 49);
		txtrRomLedig.setBackground(Color.WHITE);
		txtrRomLedig.setEditable(false);
		txtrRomLedig.setLineWrap(true);
		txtrRomLedig.setText("Rom status!");
		contentPanel.add(txtrRomLedig);
		
		lblTittel = new JLabel("Tittel:");
		lblTittel.setBounds(12, 117, 39, 16);
		contentPanel.add(lblTittel);
		
		lblBeskrivelse = new JLabel("Beskrivelse:");
		lblBeskrivelse.setBounds(12, 227, 66, 16);
		contentPanel.add(lblBeskrivelse);
		
		lblOpprettAvtale = new JLabel("Opprett avtale");
		lblOpprettAvtale.setFont(new Font("Segoe UI", Font.BOLD, 16));
		lblOpprettAvtale.setBounds(12, 6, 216, 37);
		contentPanel.add(lblOpprettAvtale);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
